<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<html>
<head>
    <script type="text/javascript">
        var listUrl="video/videoList.do";  //列表展示url
        var StatusJson;
        var statusJson;
        $(document).ready(function () {
            statusJson = changeCharset(syncGetDictListByTypeName('status'));
            StatusJson=syncGetDictListByTypeName('status');
            commonDataGrid(); //加载表格
            pagination(); // 分页
        })//end ready

        $("#submit-search").click(function () {
            $('#video-dg').datagrid({ queryParams: form2Json("fms") });   //点击搜索
        });

        // 表格
        function commonDataGrid(){
            $("#video-dg").datagrid({
                loadMsg: '数据加载中....',
                pagination: true,
                rownumbers: true,
                width: '100%',
                url: listUrl,
                nowrap: false,
                striped: true,
                sortName: 'id',
                sortOrder: 'asc',
                remoteSort: false,
                fitColumns:true,//宽度自适应
                rownumbers: true,
                pagination: true,
                pageList : [ 10, 15, 20, 25 ],
                frozenColumns: [[
                    {field: 'id', checkbox: true},
                ]],
                columns: [
                    [
                        {field: 'title', title: '标题',width : 100},
                        {field: 'videoUrl', title: '视频url',width : 100},
                        {field: 'remark', title: '备注',width : 100},
                        {field: 'status', title: '状态',width : 100,formatter : function(val) {
                            return formatDictValue(val, StatusJson);
                        }}
                    ]
                ]
            });// end datagrid
        }
        // 分页
        function pagination(){
            //设置分页控件
            var p = $('#video-dg').datagrid('getPager');
            $(p).pagination({
                pageSize: 10,//每页显示的记录条数，默认为10
                pageList: [10, 15, 20, 25 ],//可以设置每页记录条数的列表
                beforePageText: '第',//页数文本框前显示的汉字
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
                onBeforeRefresh: function () {
                    $(this).pagination('loading');
                    $(this).pagination('loaded');
                }

            });
        }//end pagination


        function newVideo() {
            var url = "video/add.do";
            $.post(url, {},
                function(data) {
                    $("#center").empty();
                    $("#center").html(data);
                    $.parser.parse($("#center"));
                });
            console.info(url);
        }

        function editVideo() {
            var rows = $('#video-dg').datagrid('getSelections');

            if (rows.length != 1) {
                $.messager.alert('操作提示', "请先选择一条要编辑的信息！");
                return;
            }
            var row = $('#video-dg').datagrid('getSelected');
            var id = row.id;

            var url = "video/edit.do";
            $.post(url, row, function (data) {
                $("#center").empty();
                $("#center").html(data);
                $.parser.parse($("#center"));
            });
        };
        function removeVideo() {
            var array = $('#video-dg').datagrid('getSelections');
            var ids = new Array();

            for (var i = 0; i < array.length; i++) {//组成一个字符串，ID主键之间用逗号隔开
                ids[i] = array[i].id;
            }
            ids = ids.join(',');
            if (array != "") {
                $.messager.defaults = {
                    ok: "确定",
                    cancel: "取消"
                };
                $.messager.confirm('操作提示', '是否要删除该信息？', function (r) {
                    if (r) {
                        $.post('video/videoDel.do', {
                            ids: ids
                        }, function (response) {

                            if (response.retCode == "0000") {
                                $('#video-dg').datagrid('reload');
                                $.messager.alert('操作提示', "删除成功", 'info');
                            } else {
                                $.messager.alert('操作提示', "删除失败", 'error');
                            }
                        });
                    }
                });
            } else {
                $.messager.alert('操作提示', "请先选择要删除的信息！");
            }
        };
    </script>
</head>
<body>
<!-- <div class="breadcrumb">系统 &gt;&gt; 组织结构管理</div> -->
<div class="linkbar"><a>短视频管理</a></div>
<div class="formtoolbar">
    <form id="fms" method="post" novalidate>
        <i>标题:</i>
        <input name="title"  class="easyui-validatebox" />
        <a id="submit-search" class="easyui-linkbutton">查询</a>
    </form>
</div>


<div class="clear"></div>
<div id="video-dg" toolbar="#toolbar"></div>

<div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add"    plain="true"	onclick="newVideo()">添加</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit"   plain="true" onclick="editVideo()">编辑</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeVideo()">删除</a>
</div>


</body>
</html>